
function checkPhoneNumber(phoneNumber) {
    // 使用正则表达式检查手机号
    const phoneNumberRegex = /^1[3-9][0-9]{9}$/;
    return phoneNumberRegex.test(phoneNumber);
}

function startCountdown() {
    let countdown = 60; // 初始倒计时时间
    // 获取验证码按钮
    const getVerificationCodeButton = document.getElementById("sendVerificationCode");
    const phoneNumber = document.getElementById('phonenumber');
    if (checkPhoneNumber(phoneNumber.value)) {
        $.ajax({
            url: "http://localhost:8080/smsC/send?phoneNumber=" + phoneNumber.value,
            type: "post",
            async: false,
            cache: false,
            success: function (res) {
                if (res.code == 0) {
                    // 禁用按钮
                    getVerificationCodeButton.disabled = true;

                    // 更新按钮文本和倒计时
                    function updateButton() {
                        if (countdown <= 0) {
                            // 倒计时结束，启用按钮
                            getVerificationCodeButton.textContent = "获取验证码";
                            getVerificationCodeButton.disabled = false;
                        } else {
                            // 更新按钮文本和倒计时
                            getVerificationCodeButton.textContent = countdown + "秒后重新获取";
                            countdown--;
                            setTimeout(updateButton, 1000);
                        }
                    }

                    updateButton();
                } else {
                    alert(res.message);
                }
            },
            error: function () {
                alert("验证码发送失败");
            }
        })

    } else {
        alert('手机号格式不正确');
    }
}


